//
//  MLAChoosePhotosCell.m
//  MagicLampApp
//
//  Created by Zheng on 2018/12/20.
//  Copyright © 2018 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAChoosePhotosCell.h"

@implementation MLAChoosePhotosCell {
    UIImageView *photoImgv;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        photoImgv = [[UIImageView alloc] init];
        photoImgv.layer.cornerRadius = 5;
        photoImgv.layer.borderColor = CX_GetColorHex(0xDCDCDC, 1).CGColor;
        photoImgv.layer.borderWidth = 1;
        photoImgv.layer.masksToBounds = YES;
        [self.contentView addSubview:photoImgv];
        [photoImgv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_deleteBtn setImage:[UIImage imageNamed:@"close_p_icon"] forState:UIControlStateNormal];
        [_deleteBtn addTarget:self action:@selector(deletePhotoAction) forControlEvents:UIControlEventTouchUpInside];
        _deleteBtn.hidden = YES;
        [self.contentView addSubview:_deleteBtn];
        [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.equalTo(self);
            make.height.width.mas_equalTo(20);
        }];
    }
    return self;
}


- (void)setIsAdd:(BOOL)isAdd {
    _isAdd = isAdd;
    if (_isAdd) {
        photoImgv.image = [UIImage imageNamed:@"add_p_icon"];
        _deleteBtn.hidden = YES;
    } else {
        _deleteBtn.hidden = NO;
    }
}

- (void)setImage:(UIImage *)image {
    _image = image;
    photoImgv.image = _image;
}


- (void)deletePhotoAction {
    if (_deletePhotosClick) {
        _deletePhotosClick(_itemIndex);
    }
}


@end
